<template>
  <vxe-modal
      :zIndex='10'
      :showFooter='true'
      title='发票文件下载'
      ref='modal3'
      :resize="true"
      width='1000'
      height='100vh'>
    <div>
      <div class='file-type'>
        <span class='radio-tit'>请选择下载发票的格式：</span>
        <vxe-radio-group v-model="fileType">
          <vxe-radio label="pdf" content="PDF"></vxe-radio>
          <vxe-radio label="ofd" content="OFD"></vxe-radio>
          <vxe-radio label="xml" content="XML"></vxe-radio>
        </vxe-radio-group>
      </div>
      <div class='box-tit'>已选择 {{ detailTableData.length }} 条发票数据。合计不含税金额{{
          bhsje
        }}元，税额{{ se }}元，价税合计{{ jshj }}元，明细如下：
      </div>
      <vxe-table header-align="center" border :sync-resize="autoSize" ref="xTable2" show-header-overflow
                 :loading="loadingTable" :data="detailTableData">
        <vxe-column type="seq" title="序号" width="60" align="center"></vxe-column>
        <vxe-column field="fphm" align="center" header-align="center" title="发票号码"></vxe-column>
        <vxe-column field="gmfmc" align="center" header-align="center" title="购买方名称"></vxe-column>
        <vxe-column field="hjje" align="center" header-align="center" title="不含税金额"></vxe-column>
        <vxe-column field="jshj" align="center" header-align="center" title="价税合计金额"></vxe-column>
        <vxe-column field="kprq" align="center" header-align="center" title="开票日期"></vxe-column>
      </vxe-table>
    </div>
    <template v-slot:footer>
      <vxe-button @click="closeBox" status="info">取消</vxe-button>
      <vxe-button @click="downloadInvoice" status="primary">下载</vxe-button>
    </template>
  </vxe-modal>
</template>
<script>
import {mixin} from '@/utils/mixin.js'
import { vmsFullOutInvoiceFileDownload } from '@/api/fileDownload.js';

export default {
  name: 'downloadComp',
  mixins: [mixin],
  data() {
    return {
      fileType: 'pdf',
      detailTableData: [],
      autoSize: true,
      loadingTable: false,
      total: '',
      bhsje: '',
      se: '',
      jshj: ''
    }
  },
  components: {},
  // mixins: [mixin],
  created() {
  },
  mounted() {

  },
  methods: {
    closeBox() {
      this.$refs.modal3.close()
    },
    async downloadInvoice() {
      let detailTableData = this.detailTableData
      let arr = []
      detailTableData.map(item => {
        arr.push(item.fphm)
      })
      let params = {}
      params.downloadType = this.fileType
      params.fphms = arr;

      vmsFullOutInvoiceFileDownload( params,'post').then(() => {
      })
          .catch((error) => {
            console.error('文件下载失败:', error);
          });

    },
    show(detailTableData) {
      this.detailTableData = detailTableData;
      let tmp = 0
      let bhsjeTmp = 0;
      let seTmp = 0;
      let jshjTmp = 0;
      detailTableData.map(item => {
        bhsjeTmp += item.hjje
        seTmp += item.hjse
        jshjTmp += item.jshj
      })
      this.bhsje = bhsjeTmp.toFixed(2)
      this.se = seTmp.toFixed(2)
      this.jshj = jshjTmp.toFixed(2)
      this.total = tmp.toFixed(2)
      this.$refs.modal3.open()
    }
  },
}
</script>
<style lang="scss">
.file-type {
  margin-bottom: 10px;
}
</style>